package com.ctshk.rpc.booking.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ctshk.common.utils.EntityUtil;
import com.ctshk.common.utils.SnowflakeIdWorker;
import com.ctshk.rpc.booking.dto.system.stampduty.info.SupplierSystemOrderStampDutyInfoDTO;
import com.ctshk.rpc.booking.entity.SupplierSystemOrderStampDuty;
import com.ctshk.rpc.booking.mapper.SupplierSystemOrderStampDutyMapper;
import com.ctshk.rpc.booking.req.system.stampduty.add.SupplierSystemOrderStampDutyAddReq;
import com.ctshk.rpc.booking.service.ISupplierSystemOrderStampDutyService;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 系统内印花税 服务实现类
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-03-25
 */
@DubboService
public class SupplierSystemOrderStampDutyServiceImpl implements ISupplierSystemOrderStampDutyService {
    @Autowired
    SupplierSystemOrderStampDutyMapper supplierSystemOrderStampDutyMapper;

    @Override
    public void add(Long id, Long userId, LocalDateTime nowDateTime, List<SupplierSystemOrderStampDutyAddReq> supplierSystemOrderStampDutyAddReqList) {
        if (CollectionUtils.isNotEmpty(supplierSystemOrderStampDutyAddReqList)) {
            List<SupplierSystemOrderStampDuty> supplierSystemOrderStampDutyList = EntityUtil.copyList(supplierSystemOrderStampDutyAddReqList, SupplierSystemOrderStampDuty.class);
            supplierSystemOrderStampDutyList.forEach(supplierSystemOrderStampDuty -> {
                supplierSystemOrderStampDuty.setId(SnowflakeIdWorker.nextId());
                supplierSystemOrderStampDuty.setOrderId(id);

            });
            supplierSystemOrderStampDutyMapper.insertBatchSomeColumn(supplierSystemOrderStampDutyList);
        }
    }

    @Override
    public List<SupplierSystemOrderStampDutyInfoDTO> selectByOrderId(Long id) {
        QueryWrapper<SupplierSystemOrderStampDuty> shipQueryWrapper = new QueryWrapper<>();
        shipQueryWrapper.lambda().eq(SupplierSystemOrderStampDuty::getOrderId, id);
        List<SupplierSystemOrderStampDuty> supplierSystemOrderStampDutyList = supplierSystemOrderStampDutyMapper.selectList(shipQueryWrapper);
        List<SupplierSystemOrderStampDutyInfoDTO> supplierSystemOrderStampDutyInfoDTOList = EntityUtil.copyList(supplierSystemOrderStampDutyList, SupplierSystemOrderStampDutyInfoDTO.class);
        return supplierSystemOrderStampDutyInfoDTOList;
    }
}
